package com.kly.order.db.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.google.common.collect.Maps;
import com.kly.enums.ProductStatus;
import com.kly.order.ServiceUtils;
import com.kly.order.db.dao.ProductDao;
import com.kly.order.db.entity.ProductEntity;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;

/**
* User: 11437
* Date: 2023-05-31
* Time: 17:06:59.539
*/

@Repository
public class ProductDaoImpl extends AbstractBaseMapper<ProductEntity> implements ProductDao {

    @Override
    public List<ProductEntity> selectByProductCategory(String appCode, Integer productCategory) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("appCode", appCode);
        params.put("productCategory", productCategory);
        params.put("deleted", 0);
        return this.getSqlSession().selectList(this.getStatement("selectByProductCategory"), params);
    }

    @Override
    public ProductEntity getProduct(String appCode, String productCode) {
        Map<String, Object> params = ServiceUtils.getParams();
        params.put("appCode", appCode);
        params.put("productCode",productCode);
        return this.getSqlSession().selectOne(this.getStatement("getProduct"), params);
    }

    @Override
    public List<ProductEntity> selectAllProducts(String appCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("appCode", appCode);
        params.put("deleted", 0);
        params.put("status", ProductStatus.ENABLE.getStatus());
        return this.selectByParams(params);
    }

    @Override
    public ProductEntity selectByProductCode(String productCode) {

        Map<String, Object> params = Maps.newHashMap();
        params.put("productCode", productCode);
        params.put("deleted", 0);
        params.put("status", ProductStatus.ENABLE.getStatus());
        final List<ProductEntity> productEntities = this.selectByParams(params);
        if (CollectionUtils.isNotEmpty(productEntities)) {
            return productEntities.get(0);
        }
        return null;

    }
}